package com.sunye.elasticsearch.entity;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.elasticsearch.common.geo.GeoPoint;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;

import java.io.Serializable;
import java.util.List;

/**
 * 商品索引
 *
 * @author paulG
 **/
@Data
@Document(indexName = "dog_index")
@ToString
@NoArgsConstructor
@Accessors(chain = true)
public class EsDogIndex implements Serializable {

    private static final long serialVersionUID = -6856471777036048874L;

    @Id
    private String id;

    //将原先的string类型拆分为text和keyword两种类型。它们的区别在于text会对字段进行分词处理而keyword则不会进行分词。
    /**
     * 名称
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    @ApiModelProperty("名称")
    private String dogName;

    /**
     * 简介(Text分词  使用ik分词器)
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String introduct;


    /**
     * 1级分类id
     */
    @Field(type = FieldType.Integer)
    private Integer categoryFirstId;


    /**
     * 2级分类id
     */
    @Field(type = FieldType.Integer)
    private Integer categorySecondId;

    /**
     * 颜色
     */
    @Field(type = FieldType.Keyword)
    private String color;


    /**
     * 售卖状态
     */
    @Field(type = FieldType.Text)
    private String saleStatus;


    @Field(type = FieldType.Integer)
    @ApiModelProperty("狗的年龄")
    private Integer age;

    /**
     * 是否为推荐狗（Boolean类型）
     */
    @Field(type = FieldType.Boolean)
    @ApiModelProperty("是否为推荐狗")
    private Boolean recommend;

    /**
     * 狗的照片(不参与查询)
     */
    @ApiModelProperty("狗的照片")
    private String img;

    /**
     * 售卖价格
     */
    @Field(type = FieldType.Double)
    @ApiModelProperty("售卖价格")
    private Double price;

    /**
     * 销量
     */
    @Field(type = FieldType.Integer)
    @ApiModelProperty("销量")
    private Integer salesNumber;


    /**
     * fielddata = true 分组使用
     */
    @Field(type = FieldType.Text, fielddata = true)
    @ApiModelProperty("品种")
    private String dogBreed;


    @GeoPointField
    @ApiModelProperty("经纬度")
    private GeoPoint location;

    /**
     * 卖点
     */
    @Field(type = FieldType.Nested)
    private List<EsDogSellingPointIndex> sellingPointList;

    /**
     * sku
     */
    @Field(type = FieldType.Nested)
    private List<Sku> skuList;

    @Data
    public static class Sku{
        @Field(type = FieldType.Integer)
        private Integer id;
        @ApiModelProperty("标题")
        @Field(type = FieldType.Keyword)
        private String  title;
    }


    public EsDogIndex(EsDog esDog){
        if(esDog !=null){
            this.id = esDog.getId()+"";
            this.dogName = esDog.getDogName();
            this.introduct = esDog.getIntroduct();
            this.color = esDog.getColor();
            this.saleStatus = esDog.getSaleStatus();
            this.age = esDog.getAge();
            this.recommend = esDog.getRecommend();
            this.img = esDog.getImg();
            this.price = esDog.getPrice();
            this.salesNumber = esDog.getSalesNumber();
            this.dogBreed = esDog.getDogBreed();
            this.categoryFirstId = esDog.getCategoryFirstId();
            this.categorySecondId = esDog.getCategorySecondId();
        }
    }



}
